package com.tepth.remote.control.base.mvp;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tepth.remote.control.delegate.BasePermissionCheckerDelegate;

/**
 * Description:
 *
 * @author Hequn.Lee
 * @date 2018/11/8
 */
public abstract class BaseMvpDelegate<T extends BasePresenter> extends BasePermissionCheckerDelegate {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mPresenter = getPresenter();
        if (mPresenter != null) {
            mPresenter.subscribe();
        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        if (mPresenter != null) {
            mPresenter.unSubscribe();
        }
        super.onDestroyView();
    }

    /**
     * 订阅
     */
    protected T mPresenter;

    /**
     * 获得订阅
     *
     * @return 订阅
     */
    abstract public T getPresenter();
}
